public class test {
    public static void main(String[] args) {
        // 定义一个汉字字符串
        String chineseString = "汉字";

        // 遍历字符串中的每个字符
        for (int i = 0; i < chineseString.length(); i++) {
            char character = chineseString.charAt(i); // 获取字符
            byte[] bytes = chineseString.substring(i, i + 1).getBytes(); // 获取字节

            // 输出字符及其对应的字节
            System.out.println("字符: " + character + ", 字节: " + bytesToString(bytes));
        }
    }

    // 辅助方法：将字节数组转换为字符串表示
    public static String bytesToString(byte[] bytes) {
        StringBuilder builder = new StringBuilder();
        for (byte b : bytes) {
            builder.append(b & 0xFF).append(" "); // 转换为无符号整数并添加到字符串构建器
        }
        return builder.toString().trim(); // 返回字符串表示
    }
}